const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const app = require('./model/art-template');
const router = require('./router/index')
const view = require('./router/views')
const errHandel = require('errorhandler');
const session = require('express-session')
const PORT = process.env.PORT || 3000;
const config =require('./config/config.default')
require('./model/index');
const path = require('path')
const MongoStore = require('connect-mongo')


app.use(session({
    secret: config.sessionSecret,
    resave: false,
    saveUninitialized:true,
    cookie:{

    },
    store: MongoStore.create({
         mongoUrl: config.dbUrl
    })
}))
app.use('/public',express.static(path.join(__dirname,"./public")))
app.use('/node_modules',express.static(path.join(__dirname,"./node_modules")))
app.use(express.json())
app.use(express.urlencoded())
app.use('/api',router);
app.use('/',view);
app.use(morgan('dev'))
app.use(cors());
app.use(errHandel())


app.listen(PORT,()=> console.log(`正在监听${PORT}端口`));